Skip to content

fix: do not count brackets inside math, raw text and strings when escaping - #64

Open
andrader wants to merge 1 commit into
sou1118:mainfrom
andrader:fix/escape-math-brackets
Open

andrader wants to merge 1 commit into
sou1118:mainfrom
andrader:fix/escape-math-brackets

Conversation

@andrader

@andrader andrader commented Nov 7, 2026

Copy link
Copy Markdown

escape_content now ignores brackets inside equations, raw text and string literals when it decides which ] is unbalanced. Before, the ] of a half-open interval closed the enclosing content argument early, and the real closing bracket was escaped:

#diff-added[Text #emph[a $(0, 1]$ b\] end.]   // before: unclosed delimiter
#diff-added[Text #emph[a $(0, 1]$ b] end.]    // after

The ranges come from typst_syntax::parse (Equation, Raw and Str nodes), so \$, quotes inside math and raw fences follow Typst's own rules. If the parser reports an error inside a node (for example a fragment cut in the middle of an equation), that node's brackets are counted as before.

Tests: three unit tests (an unpaired ] or [ in math, brackets in raw text and strings, a stray ] outside math still escaped) and three integration tests (added block, deleted block, and $[0, 1)$ with raw and string variants), each checking the exact output and that it parses. cargo fmt --check, cargo clippy -- -D warnings, cargo test and both compile-test fixtures pass.

Fixes #62

…aping (sou1118#62)

escape_content counted every `[` and `]` to find the unbalanced `]` of an
added or deleted block, so an unpaired bracket in an equation such as the
half-open interval `$(0, 1]$` closed the enclosing `#emph[` early and the
real closing bracket was escaped.

Equations, raw text and string literals are now located with the Typst
parser and skipped when counting. A node that contains a syntax error
(a fragment cut inside an equation) is not trusted and is counted as before.
Copilot AI balanced review requested due to automatic review settings November 7, 2026 22:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@coderabbitai

coderabbitai Bot commented Nov 7, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 39 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1e597ed9-0ad5-45a5-98bd-5c5a5666d4de
Commits

Reviewing files that changed from the base of the PR and between d7d062b and cbae975.

Files selected for processing: 2

  • src/render.rs
  • tests/integration.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unpaired ] inside an inline equation makes escape_content escape the wrong bracket in added or deleted blocks

2 participants